﻿@using hc.epm.DataModel.Business;
@using hc.epm.Common;
@using hc.Plat.Common.Extend;
@model Epm_TzProjectProposal
@{
    ViewBag.Title = "加油站项目编辑";
}

<link href="~/Resource/css/ProjectManagement.css" rel="stylesheet" />


<div class="contentData">
    <form class="form-horizontal" id="mainForm">
        <div class="module-div">
            <h4>项目基本信息</h4>
            <table class="datalist" style="word-break:break-all;word-wrap:break-word;margin-top:10px;">
                <tbody>
                    <tr>
                        <td class="table_title">
                            <i class="color_red_x">*</i>
                            <span>
                                项目名称
                            </span>
                        </td>
                        <td colspan="3">
                            <div class="form-group">
                                <input id="ProjectName" type="text" name="ProjectName" class="form-control" placeholder="请输入项目名称" value="@Model.ProjectName" />
                                <input id="ProjectId" type="hidden" name="Id" class="form-control" value="@Model.Id" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="table_title">
                            <i class="color_red_x">*</i>
                            <span>
                                项目性质
                            </span>

                        </td>
                        <td class="td-div">
                            <div class="form-group">
                                @Html.DropDownList("ProjectNatureType", ViewBag.ProjectNature as SelectList, null, new { @class = "form-control" })
                            </div>
                            <input id="NatureName" type="hidden" name="NatureName" value="@Model.NatureName" />
                            <input id="Nature" type="hidden" name="Nature" value="@Model.Nature" />
                        </td>
                        <td class="table_title">
                            <i class="color_red_x">*</i>
                            <span>
                                提出时间
                            </span>
                        </td>
                        <td class="apply_time td-div">
                            <div class="form-group">
                                <input type="text" class="form-control position_rel" id="ApplyTime" name="ApplyTime" onClick="WdatePicker({ el: 'ApplyTime', onpicked: function () { $('#mainForm').data('bootstrapValidator').updateStatus('ApplyTime', 'NOT_VALIDATED', null).validateField('ApplyTime') } })" placeholder="年/月/日" value="@(Model.ApplyTime == null ?"":(Convert.ToDateTime(Model.ApplyTime).ToString("yyyy-MM-dd")))">
                                <i onClick="WdatePicker({ el: 'ApplyTime' })" class="iconfont ">&#xe7e2;</i>
                            </div>
                        </td>

                    </tr>
                    <tr>
                        <td class="table_title">
                            <i class="color_red_x">*</i>
                            <span>
                                库站名称
                            </span>

                        </td>
                        <td class="td-div">
                            <div class="form-group">

                                @{

                                    if (Model.Nature == "GAIJ" || Model.Nature == "KUOJ" || Model.Nature == "QIANJ")
                                    {
                                        <input type="text" id="StationName" name="StationName" class="form-control" placeholder="请输入库站名称" readonly style="display:inline-block;width:70.9%;" value="@Model.StationName" />
                                        <div class="btn-upload">
                                            <input type="button" id="SelectStationName" class="btn form-control" style="width: 100px;font-size: 16px;" value="选择" />
                                        </div>
                                    }
                                    else
                                    {
                                        <input type="text" id="StationName" name="StationName" class="form-control" placeholder="请输入库站名称" style="display:inline-block;width:100%;" value="@Model.StationName" />
                                        <div class="btn-upload" id="StationBtn" style="display:none">
                                            <input type="button" id="SelectStationName" class="btn form-control" style="width: 100px;font-size: 16px;" value="选择" />
                                        </div>
                                    }
                                }

                                <input type="hidden" id="StationId" name="StationId" value="@Model.StationId" />
                                <input type="hidden" id="StationCode" name="StationCode" value="@Model.StationCode" />
                            </div>
                        </td>

                        <td class="table_title">
                            <i class="color_red_x">*</i>
                            <span>
                                项目类型
                            </span>

                        </td>
                        <td class="td-div">
                            <div class="form-group">
                               @Html.DropDownList("ProjectTypeName", ViewBag.ProjectType as SelectList, null, new { @class = "form-control" })
                                <input id="ProjectType" type="hidden" name="ProjectType" value="@Model.ProjectType" />
                            </div>

                        </td>
                    </tr>
                    <tr>
                        <td class="table_title">地市公司</td>
                        <td class="td-div">
                            <input type="text" id="CompanyName" name="CompanyName" class="form-control" placeholder="" readonly value="@ViewBag.CompanyName" />
                            <input type="hidden" id="CompanyId" name="CompanyId" value="@ViewBag.CompanyId" />
                        </td>
                        <td class="table_title">项目编码</td>
                        <td class="td-div">
                            <input type="text" id="ProjectCode" name="ProjectCode" class="form-control" placeholder="请输入项目编码" value="@Model.ProjectCode" />
                        </td>
                    </tr>
                    <tr>
                        <td class="table_title">推荐人姓名</td>
                        <td class="td-div">
                            <input type="text" name="Recommender" class="form-control" placeholder="请输入推荐人姓名" value="@Model.Recommender" />
                        </td>
                        <td class="table_title">
                            推荐人职务
                        </td>
                        <td class="td-div">
                            <input type="text" name="RecommenderJob" class="form-control" placeholder="请输入推荐人职务" value="@Model.RecommenderJob" />
                        </td>
                    </tr>
                    <tr>
                        <td class="table_title">推荐人单位</td>
                        <td colspan="2">
                            <div class="form-group">
                                <input id="Project_name" type="text" name="RecommenderDept" class="form-control " placeholder="请输入推荐人单位" value="@Model.RecommenderDept" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="table_title">
                            <i class="color_red_x">*</i>
                            <span>
                                申报人
                            </span>
                        </td>
                        <td colspan="2">
                            <div class="form-group">
                                <input type="text" name="DeclarerUser" id="DeclarerUser" class="form-control apply_person" value="@Model.DeclarerUser" placeholder="请选择申报人" readonly />

                                <div class="btn-upload">
                                    <input type="button" id="SelectDeclarerUser" class="btnUploadFile btn  form-control" style="width: 100px;font-size: 16px;" value="选择申报人" />
                                </div>
                                <input type="hidden" name="DeclarerUserIds" id="DeclarerUserIds" value="@Model.DeclarerUserIds">
                                <input type="hidden" id="OldDeclarerUser" value="@Model.DeclarerUser">
                                <input type="hidden" id="OldDeclarerUserIds" value="@Model.DeclarerUserIds">
                            </div>
                        </td>
                        <td>
                            <div class="color_red text_lf">(多个申报人之间用“、”隔开)</div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="module-div">
            <h4>油站信息</h4>
            <table class="datalist" style="word-break:break-all;word-wrap:break-word;margin-top:10px;">
                <tbody>
                    <tr>
                        <td class="table_title">
                            <i class="color_red_x">*</i>
                            <span>
                                地理位置
                            </span>
                        </td>
                        <td class="td-div">
                            <div class="form-group">
                                @Html.DropDownList("PositionType", ViewBag.GeographicDosition as SelectList, null, new { @class = "form-control" })

                                <input id="Position" type="hidden" name="Position" value="@Model.Position" />
                                <input id="PositionType" type="hidden" name="PositionType" value="@Model.PositionType" />
                            </div>
                        </td>
                        <td class="table_title">
                            <span>
                                项目地理位置
                            </span>
                        </td>
                        <td class="td-div">
                            <div class="form-group">
                                <input type="text" name="ProjectAddress" class="form-control" placeholder="请输入项目地理位置" value="@Model.ProjectAddress" />
                            </div>
                        </td>
                    </tr>


                    <tr>
                        <td class="table_title ">
                            <span>加油站类别</span>
                        </td>
                        <td class="td-div">
                            @Html.DropDownList("StationType", ViewBag.GasStationType as SelectList, null, new { @class = "form-control" })
                            <input id="StationType" type="hidden" name="StationType" value="@Model.StationType" />
                            <input id="StationTypeName" type="hidden" name="StationTypeName" value="@Model.StationTypeName" />
                        </td>
                        <td class="table_title">
                            <span>
                                估计金额
                            </span>
                        </td>
                        <td class="td-div">
                            <div class="form-group">
                                <input type="text" name="PredictMoney" class="form-control input_unit" placeholder="请输入估计金额" value="@(Model.PredictMoney.ToString("0.00"))" /><span>万元</span><i style="color:white;">/</i>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td class="table_title">
                            <span>
                                估计气日销量(CNG)
                            </span>
                        </td>
                        <td class="td-div">
                            <div class="form-group">
                                <input type="text" name="CNG" class="form-control input_unit" placeholder="请输入估计气日销量(CNG)千方" value="@(Model.CNG.ToString("0.00"))" /><span>千方</span><i style="color:white;">/</i>
                            </div>
                        </td>
                        <td class="table_title">
                            <span>
                                估计气日销量(LNG)
                            </span>
                        </td>
                        <td class="td-div">
                            <div class="form-group">
                                <input type="text" name="LNG" placeholder="请输入估计气日销量(LNG)千方" class="form-control input_unit" value="@(Model.LNG.ToString("0.00"))" /><span>千方</span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="table_title">
                            <i class="color_red_x">*</i>
                            <span>
                                估计油日销量
                            </span>
                        </td>
                        <td class="td-div">
                            <div class="form-group">
                                <input type="text" name="OilSalesTotal" class="form-control input_unit" placeholder="请输入估计油日销量金额" value="@(Model.OilSalesTotal.ToString("0.00"))" /><span>吨</span>
                            </div>
                        </td>
                        <td colspan="2"></td>
                    </tr>
                </tbody>
            </table>
        </div>

        @*附件上传改造 start ---- *@
        <div class="module-div">
            <h4>附件上传</h4>
            <table class="datalist fileShow" style="word-break:break-all;word-wrap:break-word;margin-top:10px;">
                <tbody class="fileShow-append">
                    <tr class="headtr">
                        <td style="width:300px;">附件类型</td>
                        <td class="td-div" style="width: 570px!important;">
                            @Html.Raw(Html.DropDownList("FileType", ViewBag.AnnexType as SelectList, null, new { @class = "form-control sel" }))
                            <input id="FileType" type="hidden" name="FileType" value="" />
                        </td>
                        <td class="table_title text_lf" colspan="3">
                            <div class="btn-upload" style="display:inline-block">
                                <input type="button" id="btnUploadFile1" class="btnUploadFile btn  form-control" style="position: relative; z-index: 1;width: 100px;font-size: 16px;" value="选择附件" />
                                <input type="file" id="loadFile1" name="loadFile1" style="display:none!important" onchange="uploadFile1()">
                                <span style="vertical-align:bottom; margin-left:15px; color:#B7B7B7;"></span>
                            </div>
                            <div class="color_red" style="display:inline-block;margin-left:20px;">附件类型仅支持：doc,pdf,excel,ppt,png等</div>
                        </td>
                    </tr>
                    <tr class="headtr">
                        <th class="table_title" style="width: 219px;">序号</th>
                        <th class="td-div" style="width: 570px!important;">附件名称</th>
                        <th class="td-div">附件类型</th>
                        <th class="td-div">附件归属</th>
                        <th class="table_title" style="width: 219px;">操作</th>
                    </tr>
                    @if (Model.TzAttachs != null && Model.TzAttachs.Count() > 0)
                    {
                        foreach (var item in Model.TzAttachs)
                        {
                            <tr>
                                <td><span class='sort'>@item.Sort</span></td>
                                <td class="text_lf"><span>@item.Name</span></td>
                                <td><span>@item.TypeName</span></td>
                                <td>
                                    @if (item.Uploadtype == 1)
                                    {
                                        <label class="checkbox-inline">
                                            <input type="checkbox" name="Uploadtype1" value="" checked />上传到投资系统
                                        </label>
                                    }
                                    else if (item.Uploadtype == 2)
                                    {
                                        if (item.FilesSize < ConstString.TzMaxFileSize())
                                        {

                                            <label class="checkbox-inline">
                                                <input type="checkbox" name="Uploadtype1" value="" />上传到投资系统
                                            </label>

                                        }
                                        else
                                        {

                                            <label class="checkbox-inline">
                                                <input type="checkbox" name="Uploadtype1" value="" disabled />上传到投资系统
                                            </label>
                                        }
                                    }



                                </td>
                                <td style="text-align:center">
                                    <a class="fileDel" href="javascript:void(0)" style="color:#337ab7;">删除</a>
                                    <input type="hidden" id="updata" data-id="@item.Id" data-url="@item.FilePath" data-src="@item.FilePath" data-name="@item.Name" data-size="@item.Size" data-time="@(Convert.ToDateTime(item.CreateTime).ToString("yyyy-MM-dd"))" data-typename="@item.TypeName" data-typeno="@item.TypeNo">
                                </td>
                            </tr>
                        }
                    }
                </tbody>
            </table>
        </div>
        @*附件上传改造 end ---- *@

        <div class="layui-form-item  btn-save" style="margin-top:60px;text-align:center;">
            <input type="button" lay-submit lay-filter="sub" value="暂&nbsp;&nbsp;&nbsp;存" class="layui-btn layui-btn-big save" data-state="@(PreProjectState.WaitSubmitted.GetValue().ToString())" />
            <input type="button" lay-submit lay-filter="sub" value="提交审核" class="layui-btn layui-btn-big save" data-state="@(PreProjectState.WaitApproval.GetValue().ToString())" />
            <input type="button" id="close" value="返&nbsp;&nbsp;&nbsp;回" class="layui-btn layui-btn-big " />
            <input type="hidden" name="fileDataJsonFile" id="fileDataJsonFile">
            <input type="hidden" name="State" id="State" />
        </div>
    </form>
</div>
<script>
    $(function () {
        $("#ProjectNatureType").change(function () {
            var proNature = $("#ProjectNatureType option:selected").val();

            if (proNature == "QIANJ" || proNature == "GAIJ" || proNature == "KUOJ") {
                $("#SelectStationName").parent().show();
                $("#StationName").css("width", "70.9%");
                $("#StationName").attr("readonly", true);
                $("#StationName").val("");
                $("#StationBtn").show();
            } else {
                $("#SelectStationName").parent().hide();
                $("#StationName").css("width", "100%");
                $("#StationName").attr("readonly", false);
                $("#StationName").val("");
                $("#StationBtn").hide();
            }
        });

        //取消
        $("#close").on("click", function () {
            window.location.href = "/TzProjectProposal/index";
        });
    });

    //附件上传改造 start ----
    $('#btnUploadFile1').click(function () {
        //获取附件类型的val
        var fileTypeVal = $("#FileType").val();
        if (fileTypeVal != "") {
            document.getElementById("loadFile1").click();
        }
        else {
            layer.alert("请选择附件类型", { icon: 2 });
        }
    });

    //用于标记附件是否上传完成 isFlagFile
    var isFlagFile = true;
    function uploadFile1() {
        isFlagFile = false;
        var fileObj = document.getElementById("loadFile1").files[0]; // js 获取文件对象
        var formFile = new FormData();
        formFile.append("file", fileObj);
        var path = formFile;
        $.ajax({
            url: "/Upload/UploadHB",
            type: "POST",
            data: path,
            contentType: false,
            processData: false,
            success: function (data) {
                var index = $(".fileShow-append tr").length - 1;
                for (var i = 0; i < data.length; i++) {
                    var obj = {};
                    obj.Name = data[i].Name;
                    obj.GuidId = data[i].GuidId;
                    obj.Size = data[i].Size;
                    obj.ImageType = data[i].ImageType;
                    obj.Group = data[i].ResponseObject.FDFS_GROUP;
                    obj.Url = data[i].ResponseObject.FDFS_NAME;
                    obj.TypeNo = $("#FileType").val();
                    obj.TypeName = $("#FileType").find("option:checked").text()
                    if (data[i].ImageType == null) {
                        var imgUrl = getFileImg(obj.Name);

                        //附件归属
                        var html1 = `<label class ="checkbox-inline">
                                         <input type="checkbox" name="Uploadtype1" value="" disabled />上传到投资系统
                                     </label>
                                    `
                        var html2 = `<label class ="checkbox-inline">
                                         <input type="checkbox" name="Uploadtype1" value="" checked />上传到投资系统
                                     </label>
                                    `
                        var html = (fileObj.size > tzmaxfilesize) ? html1 : html2;

                        //附件列表
                        var odiv = `
                                    <tr id="${obj.GuidId}">
                                        <td><span  class ='sort'> `+ index + ` </span></td>
                                        <td class ="text_lf"><span >${obj.Name}</span></td>
                                        <td><span>${obj.TypeName}</span></td>
                                        <td>${html}</td>
                                        <td style="text-align:center">
                                            <a class ="fileDel" href="javascript:void(0)" style="color:#337ab7;">删除</a>
                                            <input type="hidden" id="updata" data-id="${obj.GuidId}" data-url="${obj.Url}" data-src="${imgUrl}" data-name="${obj.Name}" data-size="${obj.Size}" data-upname="${data[i].UploadName}" data-time="${new Date(formatDateByJson(data[i].UploadDate)).Format("yyyy-MM-dd")}" data-group="${obj.Group}" data-typename="${obj.TypeName}" data-typeno="${obj.TypeNo}">
                                        </td>
                                    </tr>
                           `
                        index++;
                        $('.fileShow-append').append(odiv);
                    }
                }
                return isFlagFile = true;
            }
        });
    }

    //操作申报人方法
    function getUserData(IsChecked, obj) {
        var selectedIds = $("#DeclarerUserIds").val();  // 记录已选择的 ID
        var selectedUsers = $("#DeclarerUser").val();

        if (IsChecked) {
            if (selectedIds === "") {
                selectedIds = obj.id;
                selectedUsers = obj.name;
                $("#DeclarerUserIds").val(selectedIds);
                $("#DeclarerUser").val(selectedUsers);
            }
            else {
                if (selectedIds.indexOf(obj.id) == -1) {
                    selectedIds += '、' + obj.id;
                    selectedUsers += '、' + obj.name;
                    $("#DeclarerUserIds").val(selectedIds);
                    $("#DeclarerUser").val(selectedUsers);
                }
            }
        }
        else {
            if (selectedIds.indexOf(obj.id) != -1) {
                if (selectedIds === obj.id) {
                    $("#DeclarerUserIds").val(selectedIds.replace(obj.id, ""));
                    $("#DeclarerUser").val(selectedUsers.replace(obj.name, ""));
                }
                else if (selectedIds.indexOf(obj.id) == 0) {
                    $("#DeclarerUserIds").val(selectedIds.replace(obj.id + "、", ""));
                    $("#DeclarerUser").val(selectedUsers.replace(obj.name + "、", ""));
                }
                else {
                    $("#DeclarerUserIds").val(selectedIds.replace("、" + obj.id, ""));
                    $("#DeclarerUser").val(selectedUsers.replace("、" + obj.name, ""));
                }
            }
        }
    }

    function getSelectedUserData() {
        return {
            userIds: $('#DeclarerUserIds').val(),
            userNames: $('#DeclarerUser').val()
        }
    }

    $(".fileShow .fileDel").on("click", function () {
        $(this).parent().parent().remove();
        document.getElementById('loadFile1').value = null;
        $(".fileShow-append tr:not(.headtr)").each(function (index) {
            $(this).find(".sort").text(index + 1);//重新赋值附件排序
        });
    });

    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;

        //选择地市公司
        $("#SelectCompanyName").click(function () {
            layer.open({
                type: 2,
                title: GetLayerTitle("选择分公司"),
                shadeClose: false, //点击遮罩关闭层
                area: ['800px', '600px'],
                skin: 'frame_button',
                btnAlign: 'c',
                content: '/Comm/SelectBranchCompany?selectType=1',
                btn: ["确定", "取消"],
                yes: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var obj = frames['layui-layer-iframe' + index].getSelectData();
                    if (obj.flag === false) {
                        layer.alert(obj.msg, { icon: 2 });
                    } else {
                        $("#CompanyName").val(obj.data[0].Name);
                        $("#CompanyId").val(obj.data[0].Id);
                    }
                    layer.close(index);
                },
                btn2: function (index, layero) {
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);//关闭窗口
                },
                cancel: function (index, layero) {
                },
            });
        });

        //选择库站
        $("#SelectStationName").click(function () {
            layer.open({
                type: 2,
                title: GetLayerTitle("选择库站"),
                shadeClose: false, //点击遮罩关闭层
                area: ['800px', '600px'],
                skin: 'frame_button',
                btnAlign: 'c',
                content: '/Comm/SelectOilStation',
                btn: ["确定", "取消"],
                yes: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var obj = frames['layui-layer-iframe' + index].getSelectData();
                    if (obj.flag === false) {
                        layer.alert(obj.msg, { icon: 2 });
                    } else {
                        $("#StationName").val(obj.data[0].Name);
                        $("#StationId").val(obj.data[0].Id);
                        $("#StationCode ").val(obj.data[0].Code);
                        //验证
                        $('#mainForm').data('bootstrapValidator').updateStatus("StationName", 'NOT_VALIDATED', null).validateField("StationName");
                    }
                    layer.close(index);
                },
                btn2: function (index, layero) {
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);//关闭窗口
                },
                cancel: function (index, layero) {
                },
            });
        });

        //选择申报人
        $("#SelectDeclarerUser,#DeclarerUser").click(function () {
            layer.open({
                type: 2,
                title: GetLayerTitle("选择申报人"),
                shadeClose: false, //点击遮罩关闭层
                area: ['1000px', '680px'],
                skin: 'frame_button',
                btnAlign: 'c',
                content: '/Comm/SelectUser?selectType=2',
                btn: ["确定", "取消"],
                yes: function (index, layero) {
                    var userIds = $('#DeclarerUserIds').val().split("、");
                    if (userIds.length < 3) {
                        layer.alert("申报人最少选择3人", { icon: 2 });
                    }
                    else {
                        layer.close(index);
                    }
                    $('#mainForm').data('bootstrapValidator').updateStatus('DeclarerUser', 'NOT_VALIDATED', null).validateField('DeclarerUser')
                },
                btn2: function (index, layero) {
                    $("#DeclarerUser").val($("#OldDeclarerUser").val());
                    $("#DeclarerUserIds").val($("#OldDeclarerUserIds").val());
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);//关闭窗口
                    $('#mainForm').data('bootstrapValidator').updateStatus('DeclarerUser', 'NOT_VALIDATED', null).validateField('DeclarerUser')
                },
                cancel: function (index, layero) {
                    $("#DeclarerUser").val($("#OldDeclarerUser").val());
                    $("#DeclarerUserIds").val($("#OldDeclarerUserIds").val());
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);//关闭窗口
                },
            });
        });

        //数据提交
        $(".save").click(function () {
            //附件是否上传完成 isFlagFile
            if (isFlagFile) {
                $(".save").addClass("layui-btn-disabled");
                $(".save").attr("disabled", "disabled");

                var fileDataArray = [];
                // 附件上传改造 start ----
                $(".fileShow-append tr:not(.headtr)").each(function (index, item) {
                    var uploadtype = 0;
                    var uploadtype1 = $(this).find("input[name='Uploadtype1']").is(':checked');

                    if (uploadtype1 == true) {
                        uploadtype = 1;
                    }
                    if (uploadtype1 == false) {
                        uploadtype = 2;
                    }
                    fileDataArray.push({
                        Name: $(item).find("#updata").data("name"),
                        GuidId: $(item).find("#updata").data("id"),
                        Size: $(item).find("#updata").data("size"),
                        Group: $(item).find("#updata").data("group"),
                        FilePath: $(item).find("#updata").data("url"),
                        TypeNo: $(item).find("#updata").data("typeno"),
                        TypeName: $(item).find("#updata").data("typename"),
                        Sort: index + 1,
                        Uploadtype: uploadtype
                    })
                });
                // 附件上传改造 end ----

                var fileDataJson = JSON.stringify(fileDataArray);
                $("#fileDataJsonFile").val(fileDataJson);

                //性质
                if ($("#ProjectNatureType option:selected").val() != "") {
                    $("#NatureName").val($("#ProjectNatureType option:selected").text());
                    $("#Nature").val($("#ProjectNatureType option:selected").val());
                }

                // 地理位置
                if ($("#PositionType option:selected").val() != "") {
                    $("#Position").val($("#PositionType option:selected").text());
                }

                //加油站类别：
                if ($("#StationType option:selected").val() != "") {
                    $("#StationTypeName").val($("#StationType option:selected").text());
                    $("#StationType").val($("#StationType option:selected").val());
                }

                if ($("#ProjectTypeName option:selected").val() != "") {
                    $("#ProjectType").val($("#ProjectTypeName option:selected").text());
                }

                $("#State").val($(this).data("state"));//提交或保存的状态值

                var search = $("form").serialize();

                //点击提交表单验证，点击暂存表单不验证
                if ($(this).data("state") == "@(PreProjectState.WaitApproval.GetValue().ToString())") {
                    //对表单进行验证
                    var bv = $('#mainForm').data('bootstrapValidator');
                    bv.validate();
                    if (!bv.isValid()) {
                        $(".save").removeClass("layui-btn-disabled");
                        $(".save").removeAttr("disabled");
                        return;
                    }
                }

                $.post("Edit", search, function (data) {
                    if (data.Flag) {
                        layer.msg("操作成功", { time: 1000, icon: 1 }, function () {
                            $(".save").removeClass("layui-btn-disabled");
                            $(".save").removeAttr("disabled");
                            window.location.href = "/TzProjectProposal/Index";
                        });
                    } else {
                        layer.alert(data.Message, { icon: 2 });
                        $(".save").removeClass("layui-btn-disabled");
                        $(".save").removeAttr("disabled");
                    }
                });
            }
            else {
                layer.msg("附件上传中，请稍后提交。", { time: 3000, icon: 2 });
            }
        });

        //表单验证
        $('#mainForm').bootstrapValidator({
            excluded: [':hidden'],//[':disabled', ':hidden', ':not(:visible)'] //设置隐藏组件可验证
            fields: {
                DeclarerUser: {
                    validators: {
                        notEmpty: {
                            message: '申报人不能为空'
                        }
                    }
                },
                ProjectName: {
                    validators: {
                        notEmpty: {
                            message: '项目名称不能为空'
                        },
                        stringLength: {
                            max: 100,
                            message: '项目名称不能超过100字符'
                        },
                    }
                },
                ProjectNatureType: {
                    validators: {
                        notEmpty: {
                            message: '请选择项目性质'
                        }
                    }
                },
                ProjectType: {
                    validators: {
                        notEmpty: {
                            message: '请选择项目类型'
                        }
                    }
                },
                StationName: {
                    validators: {
                        notEmpty: {
                            message: '站库名称不能为空'
                        }

                    }
                },
                ApplyTime: {
                    validators: {
                        notEmpty: {
                            message: '请选择提出时间'
                        }
                    }
                },
                PositionType: {
                    validators: {
                        notEmpty: {
                            message: '请选择地理位置'
                        },

                    }
                },
                PredictMoney: {
                    validators: {
                        regexp: {
                            regexp: /^\d+(\.\d{0,2})?$/,
                            message: "估计金额格式输入错误"
                        },
                        stringLength: {
                            max: 12,
                            message: "只能输入12位数字"
                        }
                    }
                },
                CNG: {
                    validators: {
                        regexp: {
                            regexp: /^\d+(\.\d{0,2})?$/,
                            message: "估计气日销量(CNG)格式输入错误"
                        },
                        stringLength: {
                            max: 12,
                            message: "只能输入12位数字"
                        }
                    }
                },
                LNG: {
                    validators: {
                        regexp: {
                            regexp: /^\d+(\.\d{0,2})?$/,
                            message: "估计气日销量(LNG)格式输入错误"
                        },
                        stringLength: {
                            max: 12,
                            message: "只能输入12位数字"
                        }
                    }
                },
                OilSalesTotal: {
                    validators: {
                        notEmpty: {
                            message: '估计油日销量不能为空'
                        },
                        regexp: {
                            regexp: /^\d+(\.\d{0,2})?$/,
                            message: "估计油日销量格式输入错误"
                        },
                        stringLength: {
                            max: 12,
                            message: "只能输入12位数字"
                        }
                    }
                },
                RecommenderDept: {
                    validators: {
                        stringLength: {
                            max: 50,
                            message: "只能输入50个字符"
                        }
                    }
                },
            }
        });
    });
</script>